<?php

namespace app\admin\controller;
class Online extends base
{

    //前置方法
    protected $beforeActionList = [
        'map'  =>  ['only'=>'index'],
    ];

    /**
     * 搜索
     */
    protected function map(){
        if ($this->request->isGet()) {
            $data = $this->request->param();
            $this->datas = array();
            if (!empty($data['start_time']) && !empty($data['end_time']) && (strtotime($data['start_time']) < strtotime($data['end_time']))) {
                $this->datas ['create_time'] = [
                    ['>', strtotime($data['start_time'])],
                    ['<', strtotime($data['end_time'])]
                ];
            }
            $this->datas['lang'] = cookie('think_var_admin');
        }
    }

    public function index11()
    {
        $list = $this->model
            ->order('sort desc')
            ->paginate();
        $this->assign('num', $this->model->count());
        $this->assign('list', $list);
        return $this->fetch();
    }


    /**
     * 保存
     */
    public function save()
    {
        if (!$this->request->isPost()) {
            return ajax_info('请求失败');
        }
        $data = $this->request->post();
//        $result = $this->validate($data, 'Online');
//        if (true !== $result) {
//            $this->error($result);
//        }
        if(!empty($data['id'])){
           return $this->update($data);
        }
        $data['lang']=cookie('think_var_admin');

        $res = $this->model->allowField(true)->save($data);
        if ($res) {
            return ajax_info('保存成功','y');
        } else {
            return ajax_info('添加失败');
        }
    }
}
